package com.microsoft.mcp.sample.server.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
  @ExceptionHandler(IllegalArgumentException.class)
  public ResponseEntity<ErrorResponse> handlerIllegalArgumentException(IllegalArgumentException  ex) {
    ErrorResponse error = new ErrorResponse("InvalidInput",  "Invalid input parameter: " + ex.getMessage());
    return new ResponseEntity<>(error, HttpStatus.BAD_REQUEST);
  }

  public static class ErrorResponse {
    private String code;
    private String message;

    public ErrorResponse(String code, String message) {
      this.code = code;
      this.message = message;
    }

    // Getters
    public String getCode() { return code; }
    public String getMessage() { return message; }
  }
}
